4 * @covers VersionChecker
6 class VersionCheckerTest
extends PHPUnit_Framework_TestCase
{
8 use MediaWikiCoversValidator
;
11 * @dataProvider provideCheck
13 public function testCheck( $coreVersion, $constraint, $expected ) {
14 $checker = new VersionChecker( $coreVersion );
15 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
17 'MediaWiki' => $constraint,
23 public static function provideCheck() {
25 // [ $wgVersion, constraint, expected ]
26 [ '1.25alpha', '>= 1.26', false ],
27 [ '1.25.0', '>= 1.26', false ],
28 [ '1.26alpha', '>= 1.26', true ],
29 [ '1.26alpha', '>= 1.26.0', true ],
30 [ '1.26alpha', '>= 1.26.0-stable', false ],
31 [ '1.26.0', '>= 1.26.0-stable', true ],
32 [ '1.26.1', '>= 1.26.0-stable', true ],
33 [ '1.27.1', '>= 1.26.0-stable', true ],
34 [ '1.26alpha', '>= 1.26.1', false ],
35 [ '1.26alpha', '>= 1.26alpha', true ],
36 [ '1.26alpha', '>= 1.25', true ],
37 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
38 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
39 [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
40 [ '1.26.1', '^1.26.2', false ],
41 // Accept anything for un-parsable version strings
42 [ '1.26mwf14', '== 1.25alpha', true ],
43 [ 'totallyinvalid', '== 1.0', true ],
48 * @dataProvider provideType
50 public function testType( $given, $expected ) {
51 $checker = new VersionChecker( '1.0.0' );
53 ->setLoadedExtensionsAndSkins( [
58 $this->assertEquals( $expected, $checker->checkArray( [
59 'FakeExtension' => $given,
64 public static function provideType() {
70 'FakeDependency' => '1.0.0'
77 'MediaWiki' => '1.0.0'
85 * Check, if a non-parsable version constraint does not throw an exception or
86 * returns any error message.
88 public function testInvalidConstraint() {
89 $checker = new VersionChecker( '1.0.0' );
91 ->setLoadedExtensionsAndSkins( [
93 'version' => 'not really valid',
96 $this->assertEquals( [ "FakeDependency does not have a valid version string." ],
97 $checker->checkArray( [
100 'FakeDependency' => '1.24.3',
106 $checker = new VersionChecker( '1.0.0' );
108 ->setLoadedExtensionsAndSkins( [
109 'FakeDependency' => [
110 'version' => '1.24.3',
114 $this->setExpectedException( 'UnexpectedValueException' );
115 $checker->checkArray( [
117 'FakeDependency' => 'not really valid',